<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
#studentHome {
	padding: 15px;
	background: #fff;
	border-radius: 10px;
}

.layui-inline {
	width: 30%;
}

.layui-input-block {
	margin-left: 135px;
}

.layui-form-label {
	width: 100px;
}
</style>
</head>
<body>
	<div id="studentHome">
		<fieldset class="layui-elem-field layui-field-title site-title">
			<legend>
				<a name="fixbar">班委会管理</a>
			</legend>
		</fieldset>
		<form class="layui-form white-bg radius">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">班级</label>
					<div class="layui-input-block">
						<select id="banji" lay-filter="banji" lay-search>
							<c:forEach items="${bjs}" var="bj">
									<option value="${bj.id}" <c:if test="${bj.id==bjids}">selected="selected"</c:if>>${bj.name}</option>
							</c:forEach>
						</select>
					</div>
				</div>
			</div>
		</form>
	</div>
	<table id="committee" lay-filter="committee"></table>
	<script type="text/html" id="toolbar">
<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="xinz">新增</button>
  	</div>
</script>
	<script type="text/html" id="barDemo">
<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="xiug">修改</button>
        <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>
  	</div>
</script>
	<script type="text/javascript">
	
		layui.use('form', function() {
			form = layui.form;
			form.render('select');
			form.on('select(banji)', function(data) {
				var id = $(this).attr("lay-value");
				layui.use('table', function() {
					var table = layui.table;
					table.reload('idTest', {
						url : 'committee/page',
						where : {
							bjid : id
						},
						page : {
							curr : 1
						//重新从第 1 页开始
						}
					});
				});
			});
		});
		var bjid = $("#banji").val();
		layui.use('table', function() {
			var table = layui.table;
			table.render({
				elem : '#committee',
				url : 'committee/page',
				id : 'idTest',
				where : {
					bjid : bjid
				},
				toolbar : '#toolbar',
				cols : [ [ {
					field : 'tbClass',
					title : '班级'
				}, {
					field : 'student',
					title : '学员',
					templet : function(d) {
						return d.student ? d.student.name : '';
					}
				}, {
					field : 'student',
					title : '电话',
					templet : function(d) {
						return d.student ? d.student.phone : '';
					}
				}, {
					field : 'position',
					title : '职务'
				}, {
					fixed : 'right',
					title : '操作',
					toolbar : '#barDemo',
					width : 200
				} ] ],
				page : true
			});
			table.on('rowDouble',function(obj){
			});
			
			table.on('toolbar(committee)', function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				if (obj.event === "xinz") {
					var bjid = $("#banji").val();
					layer.open({
						type : 2,
						shade : 0.3,
						title : '班委会管理',
						btn : [ '提交', '取消' ],
						shadeClose : true,
						anim : 5,
						content : 'committee/edit1?bjid='+bjid,
						area : [ '350px', '400px' ],
						yes : function(index, layero) {
							var obj = layero.find("iframe")[0].contentWindow;
							var win = top.window['layui-layer-iframe' + index];
							var bjids = win.$("#bjids").val();
							var stuid = win.$("#stu").val();
							var position = win.$("#position").val();
							$.post('committee/save1', {
								bjid : bjids,
								stuid : stuid,
								position : position
							}, function(msg) {
								layer.msg(msg);
							});
							layer.closeAll('iframe');
						},
						btn2 : function(index, layero) {
							layer.closeAll('iframe');
						},
						end:function(){
						table.reload('idTest', {
							  url: 'committee/page',
							  where : {
									bjid : bjid
								},
								page : {
									curr : 1
								//重新从第 1 页开始
								}
							});
						}
					});
				}
			});
			
			table.on('tool(committee)', function(obj) {
				var data = obj.data;
				var id = data.id;
				if (obj.event === "xiug") {
					var bjid = $("#banji").val();
					layer.open({
						type : 2,
						shade : 0.3,
						title : '班委会管理',
						btn : [ '提交', '取消' ],
						shadeClose : true,
						anim : 5,
						content : 'committee/edit1?bjid='+bjid+'&stuid='+id,
						area : [ '350px', '400px' ],
						yes : function(index, layero) {
							var obj = layero.find("iframe")[0].contentWindow;
							var win = top.window['layui-layer-iframe' + index];
							var bjids = win.$("#bjids").val();
							var stuid = win.$("#stu").val();
							var position = win.$("#position").val();
							var ids = win.$('#id').val()
							$.post('committee/save1', {
								bjid : bjids,
								stuid : stuid,
								position : position,
								id : ids
							}, function(msg) {
								layer.msg(msg);
							});
							layer.closeAll('iframe');
						},
						btn2 : function(index, layero) {
							layer.closeAll('iframe');
						},
						end:function(){
						table.reload('idTest', {
							  url: 'committee/page',
							  where : {
									bjid : bjid
								},
								page : {
									curr : 1
								//重新从第 1 页开始
								}
							});
						}
					});
				}
				if (obj.event === "del") {
					layer.confirm('确认删除？', function(index) {
						$.post('committee/delete', {
							id : id
						}, function(msg) {
							layer.msg(msg);
							table.reload('idTest', {
								  url: 'committee/page',
								  where : {
										bjid : bjid
									},
									page : {
										curr : 1
									//重新从第 1 页开始
									}
								});
						});
					});
				}
			});
		});
	</script>
</body>
</html>